package com.ws.hzuoj.admin.user.permission.web;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.ws.common.easyui.util.Page;
import com.ws.common.easyui.util.PageUtils;
import com.ws.user.permission.entity.Permission;
import com.ws.user.permission.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/admin/user/permission")
@Controller
public class PermissionWeb {


    @Autowired
    IPermissionService permissionService;

    @RequestMapping("{type}")
    public String list(@PathVariable String type){
        return  null;
    }

    @RequestMapping("/listData")
    @ResponseBody
    public Object listData(Permission permission,Page page){
        List<Permission> permissions=permissionService.list(permission,page);
        return PageUtils.getEasyUiList(permissions);
     }

    @RequestMapping("read")
    @ResponseBody
    public Object read(Permission permission){
        if(StrUtil.isNotEmpty(permission.getId())){
            permission= permissionService.read(permission.getId());
        }
        return  permission;
    }

    @RequestMapping("/save")
    @ResponseBody
    public Object save(Permission permission){
        Integer count=permissionService.save(permission);
        return  count;
     }

    @RequestMapping("/delete")
    @ResponseBody
    public Integer delete(String id){
        return  permissionService.delete(id);
    }

    @RequestMapping("/insert")
    @ResponseBody
    public Object insert(Permission permission){
        Integer count=permissionService.insert(permission);
        return  count;
    }

    @RequestMapping("/insertSelective")
    @ResponseBody
    public Object insertSelective(Permission permission){
        return permissionService.insertSelective(permission);
    }

    @RequestMapping("/update")
    @ResponseBody
    public Object update(Permission permission){
        return permissionService.update(permission);
    }

    @RequestMapping("/listAll")
    @ResponseBody
    public Object listByMap(){
        return  permissionService.listAll();
    }
}
